package com.xnyzc.lhy.finance.controller.wallet;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.util.IDUtil;
import com.xnyzc.lhy.finance.entity.wallet.OaDFreeze;
import com.xnyzc.lhy.finance.service.wallet.IOaDFreezeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;

/**
 * <p>
 * 余额冻结表 前端控制器
 * </p>
 *
 * @author cuixiaojian
 * @since 2019-10-24
 */
@RestController
@RequestMapping("/finance/oa-dfreeze")
public class OaDFreezeController {

    @Autowired
    private IOaDFreezeService iOaDFreezeService;

    /**
     * 保存冻结余额
     * @param oaDFreeze
     * @return
     */
    @PostMapping("saveFreezeBalance")
    public Rv saveFreezeBalance(@RequestBody OaDFreeze oaDFreeze) {
        return iOaDFreezeService.saveFreezeBalance(oaDFreeze);
    }

    /**
     * 修改冻结余额
     * @param orderNo
     * @param driverId
     * @param updateAmount
     * @return
     */
    @PostMapping("updateFreezeBalance")
    public Rv updateFreezeBalance(
            @RequestParam("orderNo") String orderNo,
            @RequestParam("driverId") Long driverId,
            @RequestParam("amount") BigDecimal updateAmount
    ) {
        return iOaDFreezeService.updateFreezeBanlance(orderNo, driverId, updateAmount);
    }

    @PostMapping("reFreezeBalance")
    public Rv reFreezeBalance() {
        return iOaDFreezeService.reFreezeBalance();
    }

    @GetMapping("RecordGenurater")
    public void recordGenurater() {

        String driverIdUrl = "D:\\CommonlyUsed\\java\\lhyProject\\driverId.txt";
        String amountUrl = "D:\\CommonlyUsed\\java\\lhyProject\\amount.txt";

        Integer count = 0;

        try {
            BufferedReader driverId = new BufferedReader(new InputStreamReader(new FileInputStream(new File(driverIdUrl)), "UTF-8"));
            BufferedReader amount = new BufferedReader(new InputStreamReader(new FileInputStream(new File(amountUrl)), "UTF-8"));
            String lineTxt = null;
            String amountText = null;
            System.out.println("INSERT INTO oa_d_freeze (freeze_id, driver_id, freeze_amount, freeze_date, is_freezeing, bill_type_desc, tag, create_user, create_time, update_user, update_time) VALUES");
            while ((lineTxt = driverId.readLine()) != null) {
                while ((amountText = amount.readLine()) != null) {
                    System.out.println("(" + IDUtil.nextId() + ", " + lineTxt + ", " + amountText + ", '2019-12-18 15:08:08', 0, '1', 'lhy', 1, '2019-12-10 14:59:36', 1, '2019-12-10 14:59:36'),");
                    count++;
                    break;
                }
            }

            System.out.println("共计：[" + count + "]条");

            driverId.close();
            amount.close();
        } catch (Exception e) {
            System.err.println("read errors :" + e);
        }

    }

}
